package com.ys.zero.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.ys.zero.bean.Result;
import com.ys.zero.bean.Uarticle;
import com.ys.zero.bean.User;
import com.ys.zero.biz.BizException;
import com.ys.zero.dao.UserDao;

@WebServlet("/modify/*")
public class modifyServlet extends BaseServlet{

	private static final long serialVersionUID = 1L;
	private UserDao udao = new UserDao();
	//个人信息的修改 写入数据库
	public void modifyInfo(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException{
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		int  sex = Integer.parseInt(request.getParameter("sex"));
		String hobby = request.getParameter("hobby");
		String introduction = request.getParameter("introduction");
		String constellation = request.getParameter("constellation");
		String birthday = request.getParameter("birthday");
		//获取当前会话对象
		User user = (User)request.getSession().getAttribute("loginedUser");
		
		
		try {
			if(udao.updateInfo(name, pwd, sex, introduction, hobby, constellation, birthday,user.getAccount()) == 1) {
				String json  = new Gson().toJson(new Result(1,"修改成功"));
				response.getWriter().append(json);
			}else {
				String json  = new Gson().toJson(new Result(0,"修改失败,请联系管理员"));
				response.getWriter().append(json);
			}
		} catch (BizException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	

}
